#include "common.h"
/* 
带头指针的链表非递减有序，编写算法插入x后单链表依然非递减有序
 */

void insertx(linklist &l, int x)
{
    lnode *pre = l, *p = l->next;
    while (p && p->data <= x)
    {
        pre = p;
        p = p->next;
    }
    lnode *s = new lnode;
    s->data = x;
    s->next = p;
    pre->next = s;
}
int main(int argc, char const *argv[])
{
    linklist l;
    int a[] = {2, 4, 6, 8};
    makelist(l, a, sizeof(a) / sizeof(int));
    printlist(l);
    insertx(l, 3);
    printlist(l);
    insertx(l, 1);
    printlist(l);
    insertx(l, 9);
    printlist(l);
    return 0;
}
